﻿using System.Collections.Generic;
using System.Data;
using Best.SmartCms.Dto.Enums;
using Best.SmartCms.Utility;

namespace Best.SmartCms.Service.Files
{
    public abstract class ExportExcelBaseService
    {

        /// <summary>
        /// 
        /// </summary>
        public ExportExcelBaseService(string fileName, ExportFileType type, string sheetName = "sheet1")
        {
            this.SheetName = sheetName;
            this.Type = type;
            this.FileName = fileName;
            this.ColumnWidth = new Dictionary<string, int>();
            this.ExcelSvc = new ExcelHelper(this.SheetName);
            this.FileMime = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
        }


        internal string[] ColumnNames { get; set; }
        internal string SheetName { get; set; }
        internal Dictionary<string, int> ColumnWidth { get; set; }
        internal ExcelHelper ExcelSvc;

        public string FileName { get; set; }

        public string FileMime { get; set; }

        private ExportFileType Type { get; set; }

      
        /// <summary>
        /// 导出Excel
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public abstract byte[] Export(object condition);

        /// <summary>
        /// 转DataTable 
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public abstract DataTable SwitchObjToDataTable (object list);

        /// <summary>
        /// 初始化
        /// </summary>
        internal void InitColumnWidth()
        {
            if (this.ColumnNames != null && this.ColumnNames.Length > 0)
            {
                foreach (var columnName in ColumnNames)
                {
                    this.ColumnWidth.Add(columnName, 15);
                }
            }
        }
    }
}